package com.hhxy.mapper;

import com.hhxy.model.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ghp
 * @description 针对表【tb_role(角色信息表)】的数据库操作Mapper
 * @createDate 2023-04-25 11:58:52
 * @Entity generator.model.Role
 */
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 非超级管理员，根据userId查询用户对应的角色信息
     *
     * @param userId
     * @return
     */
    List<String> selectRoleKeyByUserId(@Param("userId") Long userId);

    /**
     * 从已逻辑删除的记录中
     *
     * @param name
     * @return
     */
    @Select("select * from tb_role where is_delete = 1 and role_name = #{name}")
    Role selectDeletedRoleByName(@Param("name") String name);

    /**
     * 根据角色名删除已逻辑删除的记录
     *
     * @param name
     * @return
     */
    @Delete("delete from tb_role where is_delete = 1 and role_name = #{name}")
    boolean deleteDeletedRoleByName(String name);

    /**
     * 根据用户id查询出角色id
     *
     * @param id
     */
    @Select("select r.id from tb_role r left join tb_user_role ur on ur.role_id = r.id where ur.user_id = #{id}")
    List<Long> selectRoleIdByUserId(@Param("id") Long id);
}




